package com.zzg.datastructure.queue;

import java.util.Scanner;

/**
 * @Author zhengzg
 * @Date 2022-08-16
 * @Version v1.0
 */
public class ArrayQueueDemo {
    public static void main(String[] args) {
        // 创建一个队列
        //ArrayQueue queue = new ArrayQueue(3);
        // 创建一个环形队列
        CircleArray queue = new CircleArray(4);

        // 接收用户输入
        char key = ' ';

        Scanner scanner = new Scanner(System.in);
        boolean loop = true;

        // 输入一个菜单
        while (loop){
            System.out.println("s(show)：显示队列");
            System.out.println("e(exit)：退出程序");
            System.out.println("a(add)：添加数据到队列");
            System.out.println("g(get)：从队列取出数据");
            System.out.println("h(head)：查看队列头的数据");

            // 接收一个字符
            key = scanner.next().charAt(0);

            switch (key){
                case 's':
                    queue.list();
                    break;
                case 'a':
                    System.out.println("输入一个数: ");
                    queue.addQueue(scanner.nextInt());
                    break;
                case 'g':
                    try{
                        int data = queue.getQueue();
                        System.out.printf("取出的数据: %d\n",data);
                    } catch (Exception e){
                        System.out.println(e.getMessage());
                    }
                    break;
                case 'h':
                    try{
                        int headData = queue.headQueue();
                        System.out.printf("取出的队列头数据是：%d\t",headData);
                    } catch (Exception e){
                        System.out.println(e.getMessage());
                    }
                    break;
                case 'e':
                    scanner.close();
                    loop = false;
                    break;
                default:
                    System.out.println("别整着死出，输入屏幕上字符啊亲亲~~~~");
                    break;
            }
        }
        System.out.println("程序退出");
    }
}
